// @ts-ignore
import { request } from "./request";
interface ListDefParams {
    pageSize?: number;
    pageNum?: number;
    page?: number;
}
interface ListRowRes<T> {
    pageNum: number;
    pages: number;
    total: number;
    rows: T[];
}
export interface AccountListRes {
    userId: string;
    name: string;
    phone: string;
    organizationName: string
}
export interface OrganizationListRes {
    id: string;
    name: string;
    parentId: string;
    children: OrganizationListRes[]
}
export interface PermissionsRes {
    id: string;
    name: string;
    parentId: string;
    title: string;
    type: 'XT' | 'GZT';
    children?: PermissionsRes[]
}


const nextApi = {

    // ------------------------ 用户登录 ----------------
    checkCode: () => {
        return request<{ captcha: string }>({
            url: '/captchaImage',
            method: 'get',
        })
    },
    userLogin: (data: { password: string; name: string; code: string }) => {
        return request({
            data,
            url: '/psAccount/pcLogin',
            method: 'post',
        })
    },
    changePassword: (data: any) => {
        return request({
            data,
            url: '/psAccount/changePassword',
            method: 'post',
        })
    },

    // ------------------------ 采购计划 ----------------
    getPlanList:(params:{name?:string,publishState?:string} & ListDefParams)=>{
        return request({
            data:params,
            url: '/purchase/findByList',
            method: 'POST',
        })
    },
    addProcurementPlan:(params:any)=>{
        return request({
            data:params,
            url: '/purchase/add',
            method: 'post',
        })
    },
    changePurchaseState:(params:{id:string,publishState:string})=>{
        return request({
            params,
            url: '/purchase/publishState',
            method: 'get',
        })
    },
    selectPurchaseDetailById:(params:{id:string})=>{
        return request({
            params,
            url: '/purchase/findById',
            method: 'get',
        })
    },
    deletePurchasePlan:(params:{id:string})=>{
        return request({
            params,
            url: '/purchase/delete',
            method: 'get',
        })
    },

    // ------------------------ 检验检测 --------------------
    getList:(params:{type:string} & ListDefParams)=>{
        return request({
            data:params,
            url: '/checkNew/findByList',
            method: 'post',
        })
    },
    check:(data:any)=>{
        return request({
            data,
            url: '/checkNew/check',
            method: 'post',
        })
    },
    getCheckDetail:(params:{id:string})=>{
        return request({
            params,
            url: 'checkNew/findById',
            method: 'get',
        })
    },
    downloadTemplate:(callback:any)=>{
        return request({
            url:'/checkNew/downTemplate',
            method:'get',
            responseType:'blob'
        },callback)
    },
    importCheckResult:(data:any)=>{
        return request({
            data,
            url:'/checkNew/importCheckResult',
            method:'post'
        })
    },
    exportCheckResult:(params:{type:string},callback:any)=>{
        return request({
            params,
            url:"/checkNew/exportCheckData",
            method:'get',
            responseType:'blob'
        },callback)
    },
    // ------------------------ 物料/产品管理 ----------------
    getMaterialList:(params:{spec?:string,id?:string,materialType?:string,state?:boolean,standard?:string,inventoryType?:string,type?:string,name?:string} & ListDefParams)=>{
        return request({
            data:params,
            url: '/materialBreed/findByList',
            method: 'POST',
        })
    },
    selectDetailById:(params:{id:string})=>{
        return request({
            params,
            url: '/materialBreed/findById',
            method: 'get',
        })
    },
    selectMaterialListByType:(params:{inventoryType?:string,materialType?:string,name?:string,state?:boolean,standard?:string})=>{
        return request({
            params,
            url: '/materialBreed/findByTypeName',
            method: 'get',
        })
    },
    editMaterial:(data:any)=>{
        return request({
            data,
            url:'/materialBreed/update',
            method: 'post',
        })
    },
    downloadMaterialTpl:(params:any,callback:any)=>{
        return request({
            params,
            url: '/materialBreed/exportEditTemplate',
            method: 'get',
            responseType: 'blob'
        }, callback)
    },
    importMPData:(data:any)=>{
        return request({
            data,
            url: '/materialBreed/importData',
            method: 'post',
        })
    },
    addMaterial:(data:any)=>{
        return request({
            data,
            url:'/materialBreed/add',
            method: 'post',
        })
    },
    changeState:(params:{id:string,state:boolean})=>{
        return request({
            params,
            url: '/materialBreed/state',
            method: 'get',
        })
    },
    deleteRecord:(params:{id:string})=>{
        return request({
            params,
            url: '/materialBreed/delete',
            method: 'get',
        })
    },
    // ------------------------ 生产设备 ----------------
    getEquipmentList: () => {
        return request({
            url: '/psProductionEquipment/findProductionEquipment',
            method: 'get',
        })
    },
    editEquipmentList:(data:any)=>{
        return request({
            data,
            url:'/psProductionEquipment/updateProductionEquipment',
            method: 'post',
        })
    },
    // ------------------------ 员工管理 ----------------
    getAccountList: (params: { name?: string; organizationId?: string } & ListDefParams) => {
        return request<{ data: ListRowRes<AccountListRes> }>({
            params,
            url: '/psAccount/findPcAccountByCondition',
            method: 'get',
        })
    },
    getAccountDetail: (id: string) => {
        return request({
            params: { userId: id },
            url: '/psAccount/findPcUserByPcUserId',
            method: 'get',
        })
    },
    editAccount: (data: any) => {
        return request({
            data,
            url: '/psAccount/addPcAccount',
            method: 'post',
        })
    },
    updateAccount: (data: any) => {
        return request({
            data,
            url: '/psAccount/updatePcAccountDetail',
            method: 'put',
        })
    },
    deleteAccount: (id: string) => {
        return request({
            url: `/psAccount/removePcUserById/${id}`,
            method: 'delete',
        })
    },
    downloadAccountTpl: (callback: any) => {
        return request({
            url: `/psAccount/downloadUserTemplate`,
            method: 'post',
            responseType: 'blob'
        }, callback)
    },
    uploadAccount: (data: any) => {
        return request({
            data,
            url: '/psAccount/importUserTemplate',
            method: 'post',
        })
    },

    // ------------------------ 生产日报表 ----------------
    getStatementInfo:(params:{predictBeginTime?:string,predictEndTime?:string} & ListDefParams)=>{
        return request({
            params,
            url: '/psStatementInfo/findStatementInfo',
            method: 'get',
        })
    },
    addStatementInfo:(params)=>{
        return request({
            data:params,
            url: '/psStatementInfo/addStatementInfo',
            method: 'post',
        })
    },
    removeStatement:(params:{id:string})=>{
        return request({
            url: `/psStatement/removeStatementById/${params.id}`,
            method: 'delete',
        })
    },
    getProductionTableList:(params:{
        type?:string,
        id?:string,
        statementInfoId?:string,
        productName?:string,
        standard?:string,
        batchNumber?:string,
        productionType?:string,
        beginTime?:string,
        endTime?:string
    } & ListDefParams)=>{
        return request({
            params,
            url: '/psStatement/findStatement',
            method: 'get',
        })
    },
    //虽然是查询报表的物料，但是是查询物料的
    getOriginMaterialListById: (params: { id?: string }) => {
        return request({
            params,
            url: '/materialBreed/getSuperior',
            method: 'get',
        })
    },
    //新增
    addTable(params:any){
        return request({
            data:params,
            url: '/psStatement/addStatement',
            method: 'post',
        })
    },
    //根据品名和标准查询aps系统的计划信息
    getPlanInfo: (params: { name: string; standard: string,planName:string }) => {
        return request({
            params,
            url: '/plan/findDetailByName',
            method: 'get',
        })
    },
    //根据品名、标准、产品大类查询计划详情的投料信息(包装计划才有产品大类)
    getPlanDetail: (params: { name: string; standard: string,inventoryType?:string,planName:string }) => {
        return request({
            params,
            url: '/plan/findDetailByNSI',
            method: 'get',
        })
    },
    //导出生产日报表
    exportReportData:(callback:any)=>{
        return request({
            url:"/psStatement/exportData",
            method:"get",
            responseType:'blob'
        },callback)
    },
    //生产日报表下载导入模板
    downloadExportTemplate:(params:{type:string},callback:any)=>{
        return request({
            params,
            url:'/psStatement/downTemplate',
            method:'get',
            responseType:'blob'
        },callback)
    },
    //导入生产日报表数据
    importOfStatementInfoByType:(data)=>{
        return request({
            data,
            url:'/psStatement/importData',
            method:'post',
        })
    },
    // ------------------------ 成品/非成品库存表 ------------------
    //半成品库存表导入模板下载
    downloadHalfRawPorductsImportTemplate:(params:{type:string},callback:any)=>{
        return request({
            params,
            url:'/nonProdStock/downTemplate',
            method:'get',
            responseType:'blob'
        },callback)
    },
    //半成品库存表导入
    importHalfRawProducts:(data:any)=>{
        return request({
            data,
            url:'/nonProdStock/importData',
            method:'post',
        })
    },
    productStorageAdd:(data:any)=>{
        return request({
            data,
            url: '/materialStock/add',
            method: 'post',
        })
    },
    //修改库存
    productStorageUpdate:(data:any)=>{
        return request({
            data,
            url: '/materialStock/edit',
            method: 'post',
        })
    },
    //成品库存修改
    productStorageUpdateProd:(data:any)=>{
        return request({
            data,
            url: '/materialStock/editProd',
            method: 'post',
        })
    },
    //查询列表
    productStorageList:(params:{
        inventoryType?:string,
        batch?:string,
        endTime?:string,
        startTime?:string,
        materialType?:string,
        materialName?:string,
        qualityState?:number,
        sellDayStart?:number,
        sellDayEnd?:number,
        spec?:string,
    } & ListDefParams)=>{
        return request({
            data:params,
            url: '/materialStock/findByList',
            method: 'post',
        })
    },
    //智能预警详情
    productStorageList2:(params:{
        inventoryType?:string,
        batch?:string,
        endTime?:string,
        startTime?:string,
        materialType?:string,
        materialName?:string,
        qualityState?:number,
        sellDayStart?:number,
        sellDayEnd?:number,
        spec?:string,
    } & ListDefParams)=>{
        return request({
            data:params,
            url: 'materialStock/findByList2',
            method: 'post',
        })
    },
    //库存表导入模板
    getProductStorageImportTemplate: (inventoryType?:string,materialType?:string,callback?: any) => {
        return request({
            url: `/materialStock/exportEditTemplate?inventoryType=${inventoryType}&materialType=${materialType}`,
            method: 'get',
            responseType: 'blob'
        }, callback)
    },
    //库存表(成品)导入
    importProductStorage: (data: any) => {
        return request({
            data,
            url: '/materialStock/importProdData',
            method: 'post',
        })
    },
    //库存表(非成品)导入
    importUnProductStorage: (data: any) => {
        return request({
            data,
            url: '/medicinalStock/importData',
            method: 'post',
        })
    },
    //库存表(成品)导出
    exportPorductStorage:(callback:any)=>{
        return request({
            url:'/materialStock/exportData',
            method:'get',
            responseType:'blob'
        },callback)
    },
    //非成品新增
    rawProductStorageAdd:(data:any)=>{
        return request({
            data,
            url: '/materialStock/save',
            method: 'post',
        })
    },
    //修改非成品库存
    rawProductStorageUpdate:(data:any)=>{
        return request({
            data,
            url: '/nonProdStock/editNum',
            method: 'post',
        })
    },
    // ------------------------ 组织架构 ----------------
    getOrganizationList: (id: string) => {
        return request<{ data: OrganizationListRes[] }>({
            params: { id },
            url: '/psOrganization/findUserdataByOrganizationId',
            method: 'get',
        })
    },
    editOrganization: (data: any) => {
        return request({
            data,
            url: '/psOrganization/addOrganization',
            method: 'post',
        })
    },
    deleteOrganization: (id: string) => {
        return request({
            url: `/psOrganization/removeOrganization/${id}`,
            method: 'delete',
        })
    },
    // ------------------------ 权限 ----------------
    getPermissionsById: (params: { organizationId?: string; userId?: string }) => {
        return request<{ data: PermissionsRes[] }>({
            params,
            url: '/ypResource/findResourceByDepartmentIdAndUserId',
            method: 'get',
        })
    },
    editPermissions: (data: any) => {
        return request({
            data,
            url: '/ypResource/giveDepartmentAndUserAddResource',
            method: 'post',
        })
    },
    // ------------------------ 图片上传 ----------------
    uploadImage: (data: any) => {
        return request({
            data,
            url: '/file/uploads',
            method: 'post',
        })
    },
    // ------------------------ 半成品库存表 2025/5/27 ----------------
    //add
    addHalfRawProduct:(data:any)=>{
        return request({
            data,
            url:'/nonProdStock/save',
            method:"post"
        })
    },
    //select
    getHalfRawPorduct:(data:any)=>{
        return request({
            data,
            url:'/nonProdStock/findByList',
            method:'post'
        })
    },
    //addCheckData
    addCheckInfo:(data:any)=>{
        return request({
            data,
            url:'/nonProdStock/addCheckBatch',
            method:'post'
        })
    },
    //selectCheckInfo
    getCheckInfo:(params:any)=>{
        return request({
            params,
            url:'nonProdStock/getCheckByStockId',
            method:'get'
        })
    },
    //del checkInfo
    removeCheckInfoById:(params:any)=>{
        return request({
            params,
            url:'/nonProdStock/delById',
            method:'get'
        })
    },
    //导出半成品
    exportHalfRawData:(callback:any)=>{
        return request({
            url:'/nonProdStock/exportNonProdData',
            method:'get',
            responseType: 'blob'
        },callback)
    },
    //导出指定类型半成品
    exportHalfRawDataWithType:(params:{type2:any},callback:any)=>{
        return request({
            params,
            url:"/nonProdStock/exportNonProdDataType",
            method:'get',
            responseType:'blob'
        },callback)
    },
    //查询平衡表
    getBalanceTableData:(params:{batch:string,type:string})=>{
        return request({
            params,
            url:'/materialStatistics/getByBatch',
            method:'get'
        })
    },
    // ------------------------ 原药材库存表 2025/6/9 ----------------
    //select
    getRawMaterialTableData:(data:any)=>{
        return request({
            data,
            url:'/medicinalStock/findByList',
            method:'post'
        })
    },
    //add
    addRawMaterialData:(data:any)=>{
        return request({
            data,
            url:'/medicinalStock/save',
            method:'post'
        })
    },
    //暂存
    saveRawMaterialData:(data:any)=>{
        return request({
            data,
            url:'/medicinalStock/temp',
            method:'post'
        })
    },
    //add outStorageData
    addOutStorageData:(data:any)=>{
        return request({
            data,
            url:'/medicinalStock/saveOutRecord',
            method:'post'
        })
    },
    //select outStorageData
    getOutStorageData:(params:{medicinalStockId:string})=>{
        return request({
            params,
            url:"/medicinalStock/getOutByMedicinalStockId",
            method:'get'
        })
    },
    //add recheckData
    addRecheckData:(data:any)=>{
        return request({
            data,
            url:'/medicinalStock/saveRecheckRecord',
            method:'post'
        })
    },
    //del recheckData
    delRecheckData:(params:{recheckId:string})=>{
        return request({
            params,
            url:"/medicinalStock/delByRecheckId",
            method:'get'
        })
    },
    //get recheckData
    getRecheckData:(params:{medicinalStockId:string})=>{
        return request({
            params,
            url:"/medicinalStock/getRecheckByMedicinalStockId",
            method:'get'
        })
    },
    //export rawInfoData
    exportRawData:(data:any,callback:any)=>{
        return request({
            data,
            url:'/medicinalStock/exportMedicinalData',
            method:'post',
            responseType: 'blob'
        },callback)
    },
    // export rawTemplate
    exportRawTemplate:(callback:any)=>{
        return request({
            url:"/medicinalStock/exportEditTemplate",
            method:'get',
            responseType:'blob'
        },callback)
    },
    // ------------------------ 生产计划 2025/6/17 ----------------
    //查询计划中的非成品库存量
    getStorageOfhalfRaw:(params:{name:string,standard:string,type:string})=>{
        return request({
            params,
            url:'/nonProdStock/getStockNum',
            method:'get'
        })
    },
    //查询总库存半成品
    getStorageOfhalfRawTotal:(params:{tqwId:string})=>{
        return request({
            params,
            url:'nonProdStock/getStockCnt',
            method:'get'
        })
    },
    //查询详情中的列表
    getListDataOfDetail:(params:{id:string})=>{
        return request({
            params,
            url:"/plan/findDetailById",
            method:'get'
        })
    },
    getPowderStorage:(params:{batch?:string,name:string,standard:string,type2:string} & ListDefParams)=>{
        return request({
            params,
            url:"/nonProdStock/getZlByBatch",
            method:'get'
        })
    },
    getPelletStorage:(params:{batch?:string,name:string,standard:string,type2:string} & ListDefParams)=>{
        return request({
            params,
            url:"/nonProdStock/getTqwByBatch",
            method:'get'
        })
    },
    getYpStorage:(params:{batch?:string,name:string,standard:string} & ListDefParams)=>{
        return request({
            params,
            url:'/nonProdStock/getYpByBatch',
            method:'get'
        })
    },
    getZYCStorage:(params:{batch?:string,name:string} & ListDefParams)=>{
        return request({
            params,
            url:'/nonProdStock/getZycByBatch',
            method:'get'
        })
    },
    // 导出计划数据
    exportPlanData:(params:{planName:string},callback:any)=>{
        return request({
            params,
            url:'plan/exportProcessPlan',
            method:'get',
            responseType:'blob'
        },callback)
    },
    // ------------------------ 季度销售数据 ----------------
    exportQuarterSellEditTemplate:(callback:any)=>{
        return request({
            url: '/materialBreed/exportQuarterSellEditTemplate',
            method: 'get',
            responseType: 'blob'
        }, callback)
    },
    importQuarterSell:(data:any)=>{
        return request({
            data,
            url: '/materialBreed/importQuarterSell',
            method: 'post',
        })
    },
    // ------------------------ 发货量统计表 ----------------
    productSendStatisticsList:(params:{
        batch?:string,
        endTime?:string,
        startTime?:string,
        materialName?:string,
        name?:string,
        inventoryType?:string,
    } & ListDefParams)=>{
        return request({
            data:params,
            url: '/materialBreed/findSellRecordByList',
            method: 'post',
        })
    },
    exportProductSendStatistics:(callback:any)=>{
        return request({
            url:'/materialBreed/exportSellRecordData',
            method:'get',
            responseType:'blob'
        },callback)
    },
    selectTotal:(params:{
        batch?:string,
        endTime?:string,
        startTime?:string,
        materialName?:string,
        name?:string,
        inventoryType?:string,
    })=>{
        return request({
            data:params,
            url:'materialBreed/getSellRecordTotal',
            method:'post'
        })
    },
    //导出发货量
    exportSellRecrod:(params:{
        batch?:string,
        endTime?:string,
        startTime?:string,
        materialName?:string,
        name?:string,
        inventoryType?:string,
    },callback:any)=>{
        return request({
            data:params,
            url:'/materialBreed/exportSellRecordData',
            method:'post',
            responseType:'blob'
        },callback)
    },
    // ------------------------ 物料平衡统计表 ----------------
    getMaterialStatisticsList:(params:{
        name?: string;
        batch?:number;
        type?: string;
    } & ListDefParams)=>{
        return request({
            data:params,
            url:'/materialStatistics/findByList',
            method:'post'
        })
    },
    addMaterialStatistics:(data: any)=>{
        return request({
            data,
            url:'/materialStatistics/add',
            method:'post'
        })
    },
    exportMaterialStatistics:(data:any,callback:any)=>{
        return request({
            data,
            url:'/materialStatistics/exportData',
            method:'post',
            responseType:'blob'
        },callback)
    },
    // 导出物料平衡统计模板
    exportMaterialStatisticsTemplate:(params:{type:string},callback:any)=>{
        return request({
            params,
            url:'/materialStatistics/exportEditTemplate',
            method:'get',
            responseType:'blob'
        },callback)
    },
    // 导入物料平衡统计数据
    importMaterialStatistics:(data:any)=>{
        return request({
            data,
            url:'/materialStatistics/importData',
            method:'post'
        })
    },

    //------------------------ 生产跟进表 ----------------
    productionTableDataSelect :(data:any)=>{
        return request({
            data,
            url:'/prodFollow/findByList',
            method:'post'
        })
    },
    addOrUpdateProductionTableData:(data:any)=>{
        return request({
            data,
            url:'/prodFollow/addOrUpdate',
            method:'post'
        })
    },
    // 下载生产跟进表模板
    prodFollowDownTemplate:(data:{tableType:string,idList?:string[]},callback:any)=>{
        return request({
            data,
            url:'/prodFollow/downTemplate',
            method:'post',
            responseType:'blob'
        },callback)
    },
    // 导出生产跟进总表
    prodFollowExportAllTable:(data:{name?:string,tempState?:string|number},callback:any)=>{
        return request({
            data,
            url:'/prodFollow/exportAllTable',
            method:'post',
            responseType:'blob'
        },callback)
    },
    //各表导出
    exportTableByType:(data:{tableType:string},callback:any)=>{
        return request({
            data,
            url:'/prodFollow/exportTable',
            method:'post',
            responseType:'blob'
        },callback)
    },
    //各表导入
    importTableByType:(data:any,callback:any)=>{
        return request({
            data,
            url:'/prodFollow/importTable',
            method:'post',
        },callback)
    },
}

 
export default nextApi
